#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:jidi
@file:contact_page.py
@time:2022/09/21
"""
from time import sleep

from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver


class ContactPage:
    def __init__(self, driver: WebDriver):
        self.driver = driver

    def add_contact(self, name, phone):
        self.driver.find_element(AppiumBy.ID, 'kui').click()
        self.driver.find_element(AppiumBy.CSS_SELECTOR, '[text="添加成员"]').click()
        self.driver.find_element(AppiumBy.CSS_SELECTOR, '[text="手动输入添加"]').click()
        username = self.driver.find_element(AppiumBy.ID, 'buo')
        username.send_keys(name)
        userphone = self.driver.find_element(AppiumBy.ID, 'hva')
        userphone.send_keys(phone)
        sleep(2)
        self.driver.find_element(AppiumBy.ID, 'hfc').click()
        self.driver.find_element(AppiumBy.CSS_SELECTOR, '[text="保存"]').click()
        sleep(2)
        # 回到上一页
        self.driver.find_element(AppiumBy.ID, 'ktu').click()
        sleep(2)
        # 回到通讯录主页
        self.driver.find_element(AppiumBy.ID, 'kud').click()

    def back_message(self):
        self.driver.find_element(AppiumBy.CSS_SELECTOR, '[text="消息"]').click()

